Skip to content

Pre/post-conditions annotations using Rust expressions#57

Merged
coord-e merged 4 commits intomainfrom
coord-e/annotation-v2
May 1, 2026
Merged

Pre/post-conditions annotations using Rust expressions#57
coord-e merged 4 commits intomainfrom
coord-e/annotation-v2

Conversation

@coord-e
Copy link
Copy Markdown
Owner

@coord-e coord-e commented Mar 28, 2026

Introduce thrust-macros crate, and thrust_macros::requires and thrust_macros::ensures expands to annotations using thrust::formula_fn introduced in #65

@coord-e coord-e force-pushed the coord-e/annotation-v2 branch from 809279c to 89fc507 Compare March 30, 2026 14:52
@coord-e coord-e force-pushed the coord-e/annotation-v2 branch from 89fc507 to 2958eb1 Compare March 31, 2026 13:39
@coord-e coord-e changed the title Annotations via actual Rust functions Pre/post-conditions annotations using Rust expressions Mar 31, 2026
@coord-e coord-e force-pushed the coord-e/annotation-v2 branch 2 times, most recently from ec48146 to 97f139c Compare March 31, 2026 16:46
@coord-e coord-e marked this pull request as ready for review March 31, 2026 16:49
@coord-e coord-e force-pushed the coord-e/annotation-v2 branch 5 times, most recently from 50bcc1b to a46e74d Compare May 1, 2026 10:08
@coord-e coord-e requested a review from Copilot May 1, 2026 10:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new thrust-macros proc-macro crate that lets users write #[thrust_macros::requires(<rust-expr>)] / #[thrust_macros::ensures(<rust-expr>)], expanding them into thrust::formula_fn-backed annotations (as introduced in #65). The PR also updates injected specs (std.rs) and UI tests to use the new expression-based annotation style, and wires the driver to pass --extern thrust_macros=... automatically.

Changes:

  • Introduce thrust-macros proc-macro crate implementing requires/ensures via generated #[thrust::formula_fn] helper functions.
  • Update std.rs extern specs and UI tests to use Rust-expression annotations (including *x/!x conventions for mutable models).
  • Convert repo to a workspace and update the driver (src/main.rs) to locate and link the thrust_macros proc-macro dylib at runtime.

Reviewed changes

Copilot reviewed 13 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
thrust-macros/src/lib.rs Implements the proc-macros and code generation for requires/ensures via formula_fn.
thrust-macros/Cargo.toml Defines the new proc-macro crate.
thrust-macros/Cargo.lock Adds a per-crate lockfile for thrust-macros.
src/main.rs Adds runtime detection + --extern injection for thrust_macros.
std.rs Migrates injected extern specs to the new Rust-expression annotation style.
tests/ui/pass/tuple_annot.rs Updates passing UI test to thrust_macros::{requires,ensures} syntax.
tests/ui/pass/annot_mut_term.rs Updates passing UI test to Mut::new(...) expression syntax.
tests/ui/pass/annot_exists.rs Updates passing UI test to `exists(
tests/ui/pass/annot_enum_simple.rs Updates passing UI test with Model + PartialEq to support expression-based equality.
tests/ui/fail/* Updates failing UI tests to the new macro-based syntax.
Cargo.toml Turns repo into a workspace; adds thrust-macros dependency to ensure it is built.
Cargo.lock Records thrust-macros as a dependency in the workspace lock.
.gitignore Adjusts ignore pattern for target/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.rs
Comment thread thrust-macros/src/lib.rs
Comment thread thrust-macros/src/lib.rs
Comment thread thrust-macros/src/lib.rs Outdated
Comment thread thrust-macros/src/lib.rs
Comment thread thrust-macros/src/lib.rs Outdated
coord-e and others added 4 commits May 1, 2026 23:05
Change thrust-macros expansion for extern_spec_fn functions

When the annotated function already has #[thrust::extern_spec_fn],
inject requires_path/ensures_path into the original function body
instead of generating a separate _thrust_extern_spec_ wrapper.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Replace thrust::trusted with thrust::ignored on the original fn in requires/ensures expansion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coord-e coord-e force-pushed the coord-e/annotation-v2 branch from 91d78fd to 0803ff0 Compare May 1, 2026 14:05
@coord-e coord-e merged commit ab1c684 into main May 1, 2026
6 checks passed
@coord-e coord-e deleted the coord-e/annotation-v2 branch May 1, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants